package com.chenfubing.ps.controller;

import com.chenfubing.ps.entity.User;
import com.chenfubing.ps.entity.pojo.CountPojo;
import com.chenfubing.ps.entity.pojo.WeekPojo;
import com.chenfubing.ps.entity.result.JsonResult;
import com.chenfubing.ps.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author : chenfubing
 * @createTime : 2020/5/8
 */
@RestController
public class LoginController {

    @Autowired
    private IndexService indexService;

    /**
     * 获取主页信息条数
     *
     * @return
     */
    @GetMapping("/getCountPojo")
    public JsonResult getCountPojo() {
        return new JsonResult(indexService.getCountPojo()) ;
    }

    /**
     * 获取一周门禁
     * @return
     */
    @GetMapping("/getWeekPojo")
    public JsonResult getWeekPojo()
    {

        return new JsonResult(indexService.getWeekPojo()) ;
    }



        @RequestMapping("login")
        public String login(String name, String pwd, HttpServletRequest request) {
            HttpSession session = request.getSession();

            if(name.equals("root")&&pwd.equals("root")) {
                User user = new User();
                user.setUserName(name);
                session.setAttribute("user",user);
                return "登录成功";
            } else {
                return "用户名或密码错误!";
            }
        }


}
